package de.lusiardi.webdav.xml;

import java.net.URI;
import java.net.URISyntaxException;
import java.util.logging.Logger;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;

/**
 * http://www.webdav.org/specs/rfc4918.html#ELEMENT_href
 *
 * @author Joachim Lusiardi
 */
@XmlRootElement
@XmlAccessorType(XmlAccessType.FIELD)
public class Href {

    private static final Logger logger = Logger.getLogger(Href.class.getCanonicalName());

    @XmlValue
    private String href;

    public String getHref() {
        return href;
    }

    public void setHref(String href) {
        this.href = href;
        if (!checkFormat()) {
            logger.warning(String.format("'%s' is an invalid URI.", href));
        }
    }

    public boolean checkFormat() {
        if (href == null) {
            return false;
        }
        try {
            URI urI = new URI(href);
        } catch (URISyntaxException ex) {
            return false;
        }
        return true;
    }
}
